let vm = new Vue({
    el: '#tongtai2',
    data: {
      value: "",
      lookPopup: false,    
      assignor: false,     //分配人
      writePopup: false,   
      activeName: ['1'],
      activeNames2: ['1'],
      
      
      form: {
        page: 1,
        limit: 10
      },
      loading: false, //控制加载状态
      finished: false, //控制加载状态
      dataList: [],                    //总列表
      lookList: {all:[], process:[], fabric:[], accessories:[]},                    // 查看
  
      assignorList: [],
      assignorName: "",
      assignorRemark: "",

      sureSc: "",
      sureremark: ""
    },
    methods: {
      onLoad() {
        this.form.page++;
        this.getData();
      },
      getData(searchCallback) {
        leiku.post(
          "http://dongtai.fsslpc.com/api/2020041805619757",
          {page: this.form.page,
            limit: this.form.limit,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
          (res) => {
            let data = res.data;
            if (searchCallback) {
              searchCallback(data);
            }

            if (!data.t.length) {
              this.finished = true;
              return;
            } else {
              this.dataList.push.apply(this.dataList, data.t);
              this.loading = false;
            }
  
          }
        );
      },
      // 搜索
      onSearch() {
        this.dataList = [];
        this.form.page = 1;
        if (this.value) {
          this.getData(
            (res) => {
              this.$toast.fail({message:'查无此单',duration: 2500})
            }
          );
        } else if (!this.value.length) {
          this.getData();
        }
      },
      onclear () {
        this.getData();
      },
  
      // 查看按钮
      lookPopupBtn(val) {
        this.lookList.all = val;        
        leiku.post('http://dongtai.fsslpc.com/api/2020041805683833', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
          let data = res.data.t;
          if (data.length) {
            data.forEach( v => {
              this.lookList.process.push(v)
            })
          }
          // console.log(this.lookList.process)
          this.lookList.process.some(v=> {
            if (v.state == 7) {
              this.assignorName = v.executor
            }
          })
          this.lookList.process.some(v=> {
            if (v.state == 8) {
              this.assignorRemark = v.remark
            }
          })
          // console.log(this.assignorName)
        })
        leiku.post('http://dongtai.fsslpc.com/api/2020041805615831', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
          let data = res.data.t;
          if (data.length) {
            data.forEach( v => {
              this.lookList.fabric.push(v)
            })
          }
          // console.log(this.lookList.fabric)
        })
        leiku.post('http://dongtai.fsslpc.com/api/2020041805760069', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId, tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
          let data = res.data.t;
          if (data.length) {
            data.forEach( v => {
              this.lookList.accessories.push(v)
            })
          }
          // console.log(this.lookList.accessories)
        })
        this.lookPopup = true;
      },
      closeLookPopup() {
        this.lookList.all=[];
        this.lookList.process=[];
        this.lookList.fabric=[];
        this.lookList.accessories=[];
        this.assignorName = '';
        this.assignorRemark = '';
        this.lookPopup = false;
      },
  
      // 分配人弹出层
      peoplePopupBtn(val) {
        this.lookList.all = val;
        leiku.post('http://dongtai.fsslpc.com/api/2020041805859072', {page: 1,limit: this.form.limit,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
          let data = res.data.t;
          if (data.length) {
            this.assignorList = data;
          }
          console.log(this.assignorList)
        })
        this.assignor = true;
      },
      onClose() {
        this.lookList.all = [];
        this.assignorList = [];
        this.assignor = false
      },
      // 分配人选择
      onSelect_assignorlist(val) {
        this.$dialog.confirm({title: val.Name, message: "确认分配？"})
          .then(() => {
            leiku.post('http://dongtai.fsslpc.com/api/2020041805662097', {uid: val.Id, id: this.lookList.all.TempleDevelopColorId, dh: this.lookList.all.Number,page: 1,limit: this.form.limit,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
              this.$toast({message:'分配成功！'})
              leiku.post(
                "http://dongtai.fsslpc.com/api/2020041805619757",
                {page: 1,
                  limit: this.dataList.length,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
                (res) => {
                  let data = res.data;
                  this.dataList = data.t;
                }
              );
              this.assignor = false;
              this.lookPopup = false;              
            })
            // window.location.reload();
          })
          .catch(()=>{})
      },
      // 分配人弹出层————内部
      peoplePopupBtn2() {
        leiku.post('http://dongtai.fsslpc.com/api/2020041805859072', {page: 1,limit: this.form.limit,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
          let data = res.data.t;
          if (data.length) {
            this.assignorList = data;
          }
          // console.log(this.assignorList)
        })
        this.assignor = true;
      },      
  
      // 完成按钮
      sureBtn() {
        this.$dialog.confirm({message: "确认完成？"})
          .then(() => {
            leiku.post('http://dongtai.fsslpc.com/api/2020041713176454', {page: 1,limit: this.form.limit,Id: this.lookList.all.TempleDevelopColorId,sc: this.sureSc, remark: this.sureremark,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''}, res=> {
              this.$toast({message:'确认成功！'})
              leiku.post(
                "http://dongtai.fsslpc.com/api/2020041805619757",
                {page: 1,
                  limit: this.dataList.length,Number: this.value,tongtai9102:window.localStorage.getItem("tongtai9102")? JSON.parse(window.localStorage.getItem("tongtai9102")).str : ''},
                (res) => {
                  let data = res.data;
                  this.dataList = data.t;
                }
              );
              this.lookPopup = false;
              this.writePopup = false;

            })
          })
          .catch(()=>{})
        
      }
    },
    mounted() {
      this.getData();
    },    
  })